package o;

import android.content.Context;
import android.text.Layout.Alignment;
import android.text.StaticLayout;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import com.huawei.gamebox.service.welfare.gift.bean.GiftCardBean;
import java.util.List;
import o.exp.d;
import o.exp.j;

public class fcp {
    protected eix ˊ;

    public fcp(eix o_eix) {
        this.ˊ = o_eix;
    }

    public int ॱ(Context context, List<GiftCardBean> list) {
        if (CollectCheck.isEmpty(list)) {
            return 0;
        }
        int[] iArr;
        int ˎ = ((this.ˊ.ˎ() + 0) + this.ˊ.ˋ()) + this.ˊ.ˏ();
        View inflate = LayoutInflater.from(context).inflate(j.ˊᐝ, null);
        TextView textView = (TextView) inflate.findViewById(d.ˊ);
        TextView textView2 = (TextView) inflate.findViewById(d.ˏ);
        int i = 0;
        int i2 = 0;
        int[] iArr2 = null;
        int[] iArr3 = null;
        for (GiftCardBean giftCardBean : list) {
            int i3;
            if (i2 == 0) {
                iArr3 = ॱ(textView, giftCardBean.ˊ(), this.ˊ.ˊ());
                if (iArr3[0] >= this.ˊ.ˊ()) {
                    i2 = 1;
                }
            }
            if (i == 0) {
                iArr2 = ॱ(textView2, String.valueOf(giftCardBean.ॱˊ()), this.ˊ.ʼ());
                if (iArr2[0] >= this.ˊ.ʼ()) {
                    i3 = 1;
                    iArr = iArr2;
                    if (i2 == 0 && i3 != 0) {
                        break;
                    }
                    iArr2 = iArr;
                    i = i3;
                }
            }
            i3 = i;
            iArr = iArr2;
            if (i2 == 0) {
            }
            iArr2 = iArr;
            i = i3;
        }
        iArr = iArr2;
        return ॱ(ˎ, iArr3, iArr);
    }

    protected int ॱ(int i, int[] iArr, int[] iArr2) {
        int i2;
        if (iArr != null) {
            i2 = iArr[1] + i;
        } else {
            i2 = i;
        }
        if (iArr2 != null) {
            return i2 + iArr2[1];
        }
        return i2;
    }

    protected int[] ॱ(TextView textView, String str, int i) {
        int[] iArr = new int[2];
        if (TextUtils.isEmpty(str)) {
            return iArr;
        }
        float lineSpacingMultiplier = textView.getLineSpacingMultiplier();
        StaticLayout staticLayout = new StaticLayout(str, textView.getPaint(), this.ˊ.ˎ(), Alignment.ALIGN_NORMAL, lineSpacingMultiplier, 0.0f, false);
        int lineCount = staticLayout.getLineCount();
        if (lineCount >= i) {
            if (lineCount > i) {
                staticLayout = new StaticLayout(str.substring(0, staticLayout.getLineEnd(i - 1)), textView.getPaint(), this.ˊ.ˎ(), Alignment.ALIGN_NORMAL, lineSpacingMultiplier, 0.0f, false);
            }
            iArr[1] = staticLayout.getHeight() + epv.ˋ(textView.getContext(), (int) (((float) (lineCount + 1)) * lineSpacingMultiplier));
        } else {
            iArr[1] = (staticLayout.getHeight() * 2) + epv.ˋ(textView.getContext(), (int) (((float) (lineCount + 2)) * lineSpacingMultiplier));
        }
        iArr[0] = lineCount;
        return iArr;
    }
}
